package com.hmall.order.web;
import com.hmall.order.pojo.OderDTO;
import com.hmall.order.pojo.Order;
import com.hmall.order.service.IOrderDetailService;
import com.hmall.order.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;
@Api("订单接口")
@Slf4j
@RestController
@RequestMapping("order")
@EnableFeignClients(value = "com.fallback.common.Client")
public class OrderController {


   @Autowired
   private IOrderService orderService;
   @Autowired
   private IOrderDetailService orderDetailService;

   @GetMapping("{id}")
   public Order queryOrderById(@PathVariable("id") Long orderId) {
      return orderService.getById(orderId);
   }
   @ApiOperation("创建订单接口")
@PostMapping
   public Long createOrder(@RequestBody OderDTO oderDTO){
      log.info("创建订单,oderDTO:{}",oderDTO);
      return orderService.createOrder(oderDTO);

   }
   /**
    * 根据订单id修改订单状态
    */
   @ApiOperation("根据订单id修改订单状态")
   @PutMapping("/{id}")
   public void updateOrderStatus(@PathVariable("id") Long orderId){
      log.info("订单修改,orderId:{}", orderId);
      orderService.updateStatus(orderId);

   }

   /**
    * 订单支付接口(自娱自乐)
    */
   @ApiOperation("订单支付接口")
   @GetMapping("pay")
   public void orderPay(@RequestParam("orderId") Long orderId) {
      log.info("订单支付,orderId:{}", orderId);
       orderService.orderPay(orderId);
   }

}
